import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DeptRoleEnum, RoleEnum } from 'src/role/role.enum';
import { UserSys } from 'src/user/userSys.entity';
import { FindOptionsWhere, IsNull, Not, Repository } from 'typeorm';
import { Criticize } from './criticize.entity';

@Injectable()
export class TestService {
    constructor(
        @InjectRepository(Criticize)
        public readonly criticize: Repository<Criticize>
    ) { }

    public getBasicMemberWhere(user: UserSys) {
        const where: FindOptionsWhere<UserSys> = {
            system: { id: user.system.id }
        };
        //boos获取所有在职员工
        if (user.role === RoleEnum.boos) {
            where.system = Not(IsNull())
            return where;
        }
        //总经理获取所有职场人员
        if (user.role === RoleEnum.director) {
            return where;
        }
        //人事获取所有职场人员
        if (user.dept?.deptRole === DeptRoleEnum.personnel) {
            return where;
        }
        //项目经理获取所有部门成员和总经理
        if (user.role === RoleEnum.manager) {
            // where.dept = { id: user.dept.id };
            return [where, {
                system: { id: user.system.id },
                role: RoleEnum.director
            }]
        }
        //特殊部门获取总经理
        if (!user.dept.editable && user.dept.name !== "项目部") {
            where.role = RoleEnum.director;
            return where
        }
        //普通员工获取项目经理
        where.role = RoleEnum.manager;
        return where;
    }
}
